#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  using pds = pair<double, string>;
  vector<pds> vec(n);
  vector<int> scores(m);
  for (auto &[deviation, name] : vec) {
    cin >> name;
    double sum = 0;
    for (auto &score : scores) {
      cin >> score;
      sum += score;
    }
    double ave = sum / m;
    for (auto &score : scores) {
      deviation += (score - ave) * (score - ave);
    }
  }
  sort(vec.begin(), vec.end(), [](pds &a, pds &b) {
    if (a.first == b.first) return a.second < b.second;
    return a.first > b.first;
  });
  for (int i = 0; i < min(20, (int)vec.size()); i ++) {
    cout << vec[i].second << endl;
  }
}